package com.tender.desensitization.factory.instance;

import java.util.List;

public class ListProcessFactory implements TypeProcessFactory {

    private TypeProcessFactoryFacade factoryFacade;

    public ListProcessFactory(TypeProcessFactoryFacade factoryFacade) {
        this.factoryFacade = factoryFacade;
    }

    @Override
    public boolean supports(Class<?> clazz) {
        return List.class.isAssignableFrom(clazz);
    }

    @Override
    public Object processType(Object instance) {
        if (null == instance) {
            return null;
        }
        List<Object> list = (List) instance;
        for (Object obj : list) {
            if (null == obj) {
                continue;
            }
            TypeProcessFactory processFactory = factoryFacade.getProcessFactory(obj.getClass());
            if (null != processFactory) {
                processFactory.processType(obj);
            }
        }

        return instance;
    }
}